<template>
	<view class="themeItem">
		<navigator url="/pages/play/play" class="box" v-if="!isMore">
			<view class="text-area">
				<view v-if="riddleList[0]" class="riddle-question">
					<text v-for="(riddle, index) in riddleList[0].list" :key="index" class="line-text">
						{{ riddle }}
					</text>
				</view>
			</view>
			<view class="mask">{{item.articleTitle}}</view>
			<!-- <view class="tab">3天前更新</view> -->
		</navigator>
		<navigator url="/pages/play/play" class="box more" v-if="isMore">
			<image class="pic" src="../../common/images/more.jpg" mode="aspectFill"></image>
			<view class="mask">
				<uni-icons type="more-filled" size="34" color="#fff"></uni-icons>
				<view class="text">更多</view>
			</view>
		</navigator>
	</view>
</template>

<script setup>
	import {
		computed
	} from 'vue';
	const props = defineProps({
		isMore: {
			type: Boolean,
			default: false
		},
		item: {
			type: Object,
			default: () => ({})
		}
	})

	const riddleList = computed(() => {
		// 使用正则表达式按<p>标签拆分内容
		const paragraphs = props.item.articleContent.split(/<\/?p>/g);
		// 过滤掉空字符串，并去除可能的空白
		const contentList = paragraphs.filter(Boolean).map(p => p.trim());

		return contentList.map(content => {
			// 使用正则表达式按"-&gt;"或"->"拆分每个谜语项
			const parts = content.split(/-&gt;|->/).map(part => part.trim());
			// 返回包含问题列表和答案的对象
			return {
				list: parts[0].split(/[，,、]+/).map(item => item.trim()), // 按中文逗号和英文逗号分割
				answer: parts[1] || '' // 如果没有答案部分，设置为空字符串
			};
		});
	});
</script>

<style lang="scss" scoped>
	.themeItem {
		background-color: #f8f8f8;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
		border-radius: 10px;
		transition: all 0.3s cubic-bezier(.25, .8, .25, 1);

		.box {
			height: 340rpx;
			border-radius: 10rpx;
			overflow: hidden;
			position: relative;

			// 添加对文本的样式
			.text-area {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				height: 100%;
				width: 100%;
			}

			.line-text {
				display: block;
				text-align: center;
				line-height: 1.2;
			}

			.pic {
				width: 100%;
				height: 100%;

			}

			.mask {
				width: 100%;
				position: absolute;
				bottom: 0;
				left: 0;
				background: rgba(0, 0, 0, 0.2);
				color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
				backdrop-filter: blur(20rpx);
				font-weight: 600;
				font-size: 30rpx;
			}

			.tab {
				position: absolute;
				left: 0;
				top: 0;
				background: rgba(250, 129, 90, 0.3);
				backdrop-filter: blur(20rpx);
				color: #fff;
				font-size: 22rpx; //字体不能再小，如果要小，必须用缩放
				transform: scale(0.8);
				transform-origin: left top; //默认以中心缩放，定位缩放基准点
				padding: 6rpx 14rpx;
				border-radius: 0 0 20rpx 0;
			}
		}

		.box.more {
			.mask {
				width: 100%;
				height: 100%;
				flex-direction: column;

				.text {
					font-size: 26rpx;
				}
			}

		}
	}

	.themeItem:hover {
		box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
	}
</style>